<template>
  <div>
    <el-table :infinite-scroll-disabled="disabled" v-infinite-scroll="load" stripe border :data="recycleList" infinite-scroll-delay='1000' style="width: 100%" row-key="menuId">
      <el-table-column label="序号" type="index" width="70" center></el-table-column>
      <el-table-column label="项目名称"  prop="title"></el-table-column>
      <el-table-column  label="开始时间"  prop="startTime" ></el-table-column>
      <el-table-column label="结束时间" prop="endTime"></el-table-column>
      <el-table-column  label="发布时间" prop="createTime" ></el-table-column>
      <el-table-column v-if="hasAuth('sys:project:taskNum')" label="任务数" prop="taskNum" width="90"></el-table-column>
      <el-table-column label="状态" prop="status" width="90"></el-table-column>
      <el-table-column label="操作" >
        <template slot-scope="scope">
          <el-popconfirm v-if="hasAuth('sys:project:publish')" title="是否还原该项目" @confirm="restore(scope.row.id)">
            <el-button type="text" slot="reference">还原</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <p style="width: 100%;text-align: center;color: #999;"v-if="loading">加载中...</p>
  </div>
</template>

<script>
  export default{
    data(){
      return {
        recycleList:[],
        typeInfo:{
          title:'',
          status:'',
          page:1,
          limit:10
        },
        loading:true,
        disabled:false
      }
    },
    methods:{
      async initRecycleList(){
        let  result=await this.$get('/api/project/recycleBin',this.typeInfo)
        result.data.list.map(item=>{
          item.status='已删除'
          if(!item.taskNum)item.taskNum=0
        })
        this.recycleList.push(...result.data.list)
        this.loading=this.recycleList.length!=result.data.total
        this.disabled=this.recycleList.length==result.data.total
      },
      load(){
        this.typeInfo.page++
        this.initRecycleList()
      },
      resetInfo(){
        this.recycleList=[]
        this.typeInfo.page=1
      },
      async restore(id){
         let result=await this.$post('/api/project/recover/'+id)
         if(result.code==200){
           this.$message.success(result.msg)
           this.resetInfo()
           this.initRecycleList()
         }
       }
    },
    mounted(){
      this.initRecycleList()
    }
  }
</script>

<style>
</style>
